#ifndef PARTICLE_UPDATE
#define PARTICLE_UPDATE
#include "Common.hlsl"
#include "ComputeBuffs.hlsl"

AppendStructuredBuffer<uint> Particle_pool_Update;//ready to add
ConsumeStructuredBuffer<uint> Particle_alive_Update;//ready to die
AppendStructuredBuffer<uint> Particle_alive_Update_Append;
RWStructuredBuffer<uint>test;

[numthreads(THREAD_COUNT, 1, 1)]
void Update(uint3 id : SV_DispatchThreadID)
{
    uint len=Simulation_Counter.Load(0);
    test[id.x]=666;
    if(id.x<len)
    {
        uint index=Particle_alive_Update.Consume();
        Particle p = particles[index];
        
        if(p.alive)
        {
            test[id.x]=index;
            p.life.x += time.x;
            if (p.life.x>= p.life.y)
            {
                p.alive = false;
                Particle_pool_Update.Append(id.x);
                //pre
    
            }
            else
            {
                p.position += (p.velocity) * time.x;
                Particle_alive_Update_Append.Append(id.x);
                //now
            }
            particles[id.x] = p;
        }
        else
        {
            Particle_alive_Update_Append.Append(index);
        }
    }
    
    
    
    
    
    
}
#endif
//0~990
//991~999